package com.maxatime.web.controller;


import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSONObject;
import com.maxatime.common.constant.BusinessContents;
import com.maxatime.pojo.entity.Exam;
import com.maxatime.pojo.entity.ExamPlan;
import com.maxatime.pojo.entity.ExamPlanSubjectRelation;
import com.maxatime.pojo.entity.ExamSubject;
import com.maxatime.service.ExamPlanService;
import com.maxatime.service.ExamPlanSubjectRelationService;
import com.maxatime.util.MyContent;

@Controller
@RequestMapping("/ExamPlan")
public class ExamPlanController {
	
	@Autowired
	ExamPlanService examPlanService;
	
	@Autowired
	ExamPlanSubjectRelationService examPlanSubjectRelationService;///点详情查询
	
	/**
	 * 
	 * @Title: ExamPlanController   
	 * @Description: TODO(考试计划管理)   
	 * @param: @param jsonStr
	 * @param: @return      
	 * @return: Map<String,Object>      
	 * @throws   
	 * @author: ssb    
	 * @date:   2024年2月27日 上午9:55:10   
	 * @version V1.0
	 */
	@RequestMapping("/quest")
	@ResponseBody
	public Map<String, Object> quest(@RequestBody String jsonStr){
		JSONObject jsonObj = JSONObject.parseObject(jsonStr);
		String examPlanName = jsonObj.getString("examPlanName");
		int pageNum = jsonObj.getIntValue("pageNum");
		int pageSize = jsonObj.getIntValue("pageSize");
		ExamPlan examPlan = new ExamPlan();
		examPlan.setExamPlanName(examPlanName);
		examPlan.setPageNum(pageNum);
		examPlan.setPageSize(pageSize);
		
		Map<String, Object> m = examPlanService.list(examPlan);
		m.put(BusinessContents.CODE, "0000");
		m.put(BusinessContents.MSG, "交易成功");
		m.put(BusinessContents.DATA, m.get("examPlan1"));
		m.put("pageInfo", m.get("pageInfo"));
		
		return m;
	}
	@RequestMapping("/del")
	@ResponseBody
	public Map<String, Object> del(@RequestBody String jsonStr){
		JSONObject jsonObj = JSONObject.parseObject(jsonStr);
		int pkId = jsonObj.getInteger("pkId");
		Map<String, Object> m = new HashMap<>();
		examPlanService.deleteByPrimaryKey(pkId);
		m.put(MyContent.CODE, "2222");
		m.put(MyContent.MSG, "删除成功");
		return m;
	}
	@RequestMapping("/save")
	@ResponseBody
	public Map<String, Object> save(@RequestBody ExamPlan examPlan){
		Map<String, Object> m = new HashMap<>();
		examPlanService.insertSelective(examPlan);
		m.put(MyContent.CODE, "1111");
		m.put(MyContent.MSG, "新增成功");
		return m;
	}
	@RequestMapping("/find")
	@ResponseBody
	public Map<String, Object> find(@RequestBody String jsonStr){
		JSONObject jsonObj = JSONObject.parseObject(jsonStr);
		int pkId = jsonObj.getInteger("pkId");
		Map<String, Object> m = new HashMap<>();
		ExamPlan examPlan = examPlanService.find(pkId);
		m.put(MyContent.CODE, "3333");
		m.put(MyContent.MSG, "反显成功");
		m.put(MyContent.DATA, examPlan);
		return m;
	}
	@RequestMapping("/update")
	@ResponseBody
	public Map<String, Object> update(@RequestBody ExamPlan examPlan){
		Map<String, Object> m = new HashMap<>();
		examPlanService.updateByPrimaryKeySelective(examPlan);
		m.put(MyContent.CODE, "4444");
		m.put(MyContent.MSG, "修改成功");
		return m;
	}
	
	//详情查询
		@RequestMapping("/xqquest")
		@ResponseBody
		public Map<String,Object> xqquest(@RequestBody String jsonStr){
			JSONObject jsonObj = JSONObject.parseObject(jsonStr);
			int examPlanId = jsonObj.getInteger("examPlanId");
			
			Map<String, Object> m =new HashMap<>();
			List<Exam> list = examPlanSubjectRelationService.list(examPlanId);
			System.out.println("list111:::"+list);
			m.put(MyContent.CODE, "5555");
			m.put(MyContent.MSG, "详情查询成功");
			m.put(MyContent.DATA, list);
			System.out.println("list::::!!!!"+list);
			return m;
		}
		
		//详情新增
		@RequestMapping("/XQadd")
		@ResponseBody
		public Map<String, Object> XQadd(@RequestBody ExamPlanSubjectRelation examPlanSubjectRelation){
//			JSONObject jsonObj = JSONObject.parseObject(jsonStr);
//			int examPlanId = jsonObj.getInteger("examPlanId");
			
//			ExamPlanSubjectRelation examPlanSubjectRelation = new ExamPlanSubjectRelation();
//			examPlanSubjectRelation.setExamPlanId(examPlanId);
			examPlanSubjectRelationService.insertSelective(examPlanSubjectRelation); 
			Map<String, Object> m=new HashMap<String, Object>();
			m.put(MyContent.CODE, "6666");
			m.put(MyContent.MSG, "详情新增成功");
			return m;
		}
		
		//详情新增查询下拉框
		@RequestMapping("/XQaddxlk")
		@ResponseBody
		public Map<String, Object> XQaddxlk(@RequestBody ExamSubject examSubject){
			Map<String, Object> m = new HashMap<>();
			List<ExamSubject> list =  examPlanSubjectRelationService.list(examSubject);
			m.put(MyContent.CODE, "7777");
			m.put(MyContent.MSG, "详情新增查询examSubject成功");
			m.put(MyContent.DATA, list);
			return m;
		}
}
